package com.pig.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.pig.dao.CartMapper;
import com.pig.pojo.cart.Cart;
import com.pig.pojo.order.OrderItem;
import com.pig.service.cart.DubboCartService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class DubboCartServiceImpl implements DubboCartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<OrderItem> findCartUserItems(Integer userId) {
        List<OrderItem> cartList= cartMapper.selectOrderItemsByUserId(userId);
        System.out.println(cartList.toString());
        return cartList;
    }

    @Override
    public void deleteCartByUserId(Integer userId) {
        cartMapper.deleteCartByUserId(userId);
    }
    @Override
    public List<Cart> findUserItems(Integer userId) {
        List<Cart> cartList= cartMapper.selectItemsByUserId(userId);
        System.out.println(cartList.toString());
        return cartList;
    }

    @Override
    public void changeNum(Integer cartId,Integer num) {
        cartMapper.updateNum(cartId,num);
    }

    @Override
    public void delItemCartById(Integer cartId1) {
        System.out.println(cartId1);
        //cartMapper.delItemCartById(cartId1);
        cartMapper.deleteById(cartId1);
    }

    @Override
    public void saveCart(Cart cart) {
        cartMapper.insert(cart);
    }


}
